/**
 * 
 */
package meituan;

/**
 * @author zhongfang
 *
 */
public class 子数组和为k的倍数 {

	public static int solve(int[] nums, int k) {// 特殊用例：只有一个值，有0个值，某个mod值：只有1个，只有0个
		int[][] mods = new int[k][2];
		for (int i = 0; i < mods.length; i++) {
			for (int j = 0; j < 2; j++) {
				mods[i][j] = -1;
			}
		}
		int sum = 0;
		for (int i = 0; i < nums.length; i++) {
			sum += nums[i];
			sum %= k;
			System.err.println(sum);
			if (sum == 0) {
				mods[sum][0] = -1;
				mods[sum][1] = i;
			} else {
				if (mods[sum][0] == -1) {
					mods[sum][0] = i;
				} else {
					mods[sum][1] = i;
				}
			}
		}
		int max = 0;
		for (int i = 0; i < mods.length; i++) {
			System.out.println(mods[i][0]+" "+mods[i][1]);
			max = Math.max(max, mods[i][1] == -1 ? 0 : mods[i][1] - mods[i][0]);
		}
		return max;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] nums = { 1, 2, 3, 5, 6, 7 };
		int k = 5;
		System.out.println(solve(nums, k));
	}
}
